package io.jee.runshan.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Entity
@Table(name = "runshan_weixin_menu")
@JsonIgnoreProperties(value = { "parent", "type", "menuKey" })
public class WeixinMenu {
	private Integer id;
	private Integer orderIndex;
	private Integer level; // 菜单级别
	private String type; // 菜单类型
	private Integer reType; // 响应类型（0-网络链接；1-纯文字消息；2-单图文消息；3-多图文消息；4-系统处理）
	private String name;
	private String url;
	private String menuKey; // 菜单标志key（不能重复）
	private Boolean enabled = true;
	private WeixinMenu parent;
	private Integer parentid;
	private Set<WeixinMenu> children;

	public void addChild(WeixinMenu child) {
		if (children == null) {
			children = new HashSet<WeixinMenu>();
		}
		children.add(child);
	}

	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getOrderIndex() {
		return orderIndex;
	}

	public void setOrderIndex(Integer orderIndex) {
		this.orderIndex = orderIndex;
	}

	public Boolean getEnabled() {
		return enabled;
	}

	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}

	@ManyToOne
	public WeixinMenu getParent() {
		return parent;
	}

	public void setParent(WeixinMenu parent) {
		this.parent = parent;
	}

	@Column(unique = true)
	public String getMenuKey() {
		return menuKey;
	}

	public void setMenuKey(String menuKey) {
		this.menuKey = menuKey;
	}

	@Column(name = "parent_id", insertable = false, updatable = false)
	public Integer getParentid() {
		return parentid;
	}

	public void setParentid(Integer parentid) {
		this.parentid = parentid;
	}

	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	public Integer getReType() {
		return reType;
	}

	public void setReType(Integer reType) {
		this.reType = reType;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@Transient
	public Set<WeixinMenu> getChildren() {
		return children;
	}

	public void setChildren(Set<WeixinMenu> children) {
		this.children = children;
	}

}
